// page/member/withdraw.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    index: 0,
    course: ["建设银行", "民生银行", "交通银行"],
    picker_arr: [],
    sum:''
  },

  bindPickerChange: function (e) {
    this.setData({
      index: e.detail.value
    })
  },
 
  onShow: function () {
    var app = getApp()
    var that = this;
    var uid = wx.getStorageSync('uid');
    var money = this.data.money;
    var picker_arr = []
    // console.log(uid)
    wx.request({
      url: app.globalData.host + '&g=App&m=User&a=Withdraw',
      data: { uid: uid },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
        var money = res.data.moneyMax
        that.setData({
          money: res.data.moneyMax
        })
      }
    })
    wx.request({
      url: app.globalData.host + '&g=App&m=User&a=my_card',
      data: { uid: uid },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
        var courseItem = res.data.list
        courseItem.forEach(function (e) {
          picker_arr.push(e.bankName);
        })
        that.setData({
          list: res.data.list,
          idcard: res.data.idCard,
          picker_arr: picker_arr,
        })
      }
    })
  },
  Change: function (e) {
    this.setData({
      picker_index: e.detail.value,
    })
    // console.log(this.data.picker_index)
  },
  sum: function (e) {
    this.setData({
      sum: e.detail.value,
    })
    console.log(this.data.sum)
    var sum = this.data.sum
    var money = this.data.money;
  },
  deposit:function(e){
    var app = getApp()
    var that = this;
    var uid = wx.getStorageSync('uid');
    var sum = that.data.sum;
    var money = that.data.money;
    if(sum.length<1){
      wx.showModal({
        title: '提示',
        content: '请输入需要提现的金额',
        showCancel: false,
        // mask:true,
        duration: 2000,
      })
    } else if (parseInt(sum) > parseInt(money)){
      wx.showModal({
        title: '提示',
        content: '您的可提现余额不足',
        showCancel: false,
        // mask:true,
        duration: 2000,
      })
    }else{
      wx.request({
        url: app.globalData.host + '&g=App&m=User&a=Withdraw',
        data: { uid: uid, money: this.data.sum },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          console.log(res.data)
          that.setData({
            money: res.data.moneyMax
          })
          wx.showModal({
            title: '提示',
            content: '提现成功',
            showCancel: false,
            mask: true,
            success: function (res) {
              if (res.confirm) {
                wx.switchTab({
                  url: '/page/member/member'
                })
              }
            }
          })
        }
      })
    }
  },

})